import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.URL;
import java.util.concurrent.TimeUnit;
//收藏会话

public class Test3 {

    private static AndroidDriver<AndroidElement> driver;

    public static void main(String[] args) {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName", "127.0.0.1:62001");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("noReset", true);
        capabilities.setCapability("appPackage", "com.cnezsoft.xxm");
        capabilities.setCapability("appActivity", ".MainActivity");
       

        try {
            URL appiumUrl = new URL("http://localhost:4723/wd/hub");
            driver = new AndroidDriver<>(appiumUrl, capabilities);
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

            // 进入三人小队的聊天窗口
            MobileElement contactName = driver.findElement(By.xpath("//android.widget.TextView[@text='三人小队']"));
            contactName.click();

            // 将该聊天窗口加入收藏
            MobileElement favoriteButton = driver.findElement(By.id("com.cnezsoft.xxm:id/title_bar_more"));
            favoriteButton.click();

            MobileElement addToFavoritesButton = driver.findElement(By.xpath("//android.widget.TextView[@text='收藏']"));
            addToFavoritesButton.click();

            // 验证该聊天窗口是否已加入收藏
            MobileElement favoritesTab = driver.findElement(By.xpath("//android.widget.TextView[@text='收藏']"));
            favoritesTab.click();

            MobileElement favoritedChat = driver.findElement(By.xpath("//android.widget.TextView[@text='三人小队']"));

            if (favoritedChat.isDisplayed()) {
                System.out.println("Test passed!");
            } else {
                System.out.println("Test failed!");
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            driver.quit();
        }
    }
}